import {
    createSlice
} from "@reduxjs/toolkit";
import {getHospitalSet} from "@/api/hosp";
import {useSelector} from "react-redux";
import {upLoading, upPageInfo} from "@/store/slices/common";

const hospSlice = createSlice({
    name:"hosp",
    initialState:{
        hospitalSetList:[],// 医院设置列表
    },
    reducers:{
        upHospitalSetList(state,{payload}){
            state.hospitalSetList = payload;
        }
    }
})
const {upHospitalSetList} = hospSlice.actions;
// 暴露异步action:调用医院设置列表信息
export const getHospitalSetAsync = (page:number,limit:number)=>{
    return async (dispatch:any)=>{
        dispatch(upLoading(true));
        const result = await getHospitalSet(page,limit);
        dispatch(upHospitalSetList(result.data.records));
        dispatch(upPageInfo({
            current:result.data.current,
            pageSize:result.data.size,
            total:result.data.total
        }))
        dispatch(upLoading(false));
    }
}
export const useSelectorHosp = ()=>useSelector((state:any)=>state.hosp);
export default hospSlice.reducer;
